////////////////////////////////////////////////////////////////////////////////
// Filename		PorterStemmingAlgorithm.h
// Author		outphase
// Date			2011-09-12
// Comment		
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <fstream>

class AdvancedString;

class PorterStemmingAlgorithm
{
public:
	enum FilterCode
	{
		FilterCode_Stemming = 0,
		FilterCode_SkipStemming = 1,
		FilterCode_Discard = 2,
	};

	PorterStemmingAlgorithm();
	virtual ~PorterStemmingAlgorithm();
	std::string Parse(const char* string);
	std::string Parse(std::string& string);
	void AddException(std::string& filename);
private:
	// Filtering
	FilterCode Filtering();
	// Parsing
	void Step1a();
	void Step1b();
	void Step1c();
	void Step2();
	void Step3();
	void Step4();
	void Step5();

	void CheckLastAIsStem();
	bool IsCVD(int idx);
	void r(char* string, int length);

	AdvancedString* m_String;
	std::string m_OriginalString;
	typedef std::map<std::string, std::string> ExceptionMap;
	ExceptionMap m_ExceptionMap;
};